package com.qf.filters;

import com.qf.dfa.SensitivewordFilter;
import com.qf.service.SendReportService;
import com.qianfeng.smsplatform.common.constants.InterfaceExceptionDict;
import com.qianfeng.smsplatform.common.model.Standard_Report;
import com.qianfeng.smsplatform.common.model.Standard_Submit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Set;

/*
 * @Data: 2021/7/16 16:02
 * */
@Component
public class DirtyWordsFilters implements FiltersChain {

    private SendReportService sendReportService;
    @Autowired
    public void setSendReportService(SendReportService sendReportService) {
        this.sendReportService = sendReportService;
    }

    private SensitivewordFilter sensitivewordFilter;
    @Autowired
    public void setSensitivewordFilter(SensitivewordFilter sensitivewordFilter) {
        this.sensitivewordFilter = sensitivewordFilter;
    }

    @Override
    public boolean dealSms(Standard_Submit submit) {

//        获取消息里的内容
        String messageContent = submit.getMessageContent();
//        判断 内容里面 有哪些敏感词
        Set<String> sensitiveWord = sensitivewordFilter.getSensitiveWord(messageContent);
        System.out.println("敏感词为-->"+sensitiveWord);
//      敏感词应该通知客户
        if(sensitiveWord!=null&&sensitiveWord.size()>0){
/*            Standard_Report report=new Standard_Report();
            report.setClientID(submit.getClientID());
            report.setSrcID(submit.getSrcSequenceId());
            report.setState(2);
            report.setMobile(submit.getDestMobile());
            report.setErrorCode(InterfaceExceptionDict.RETURN_STATUS_DIRTY_ERROR);
            report.setDescription(sensitiveWord.toString());
//       第几次推送   我们告诉客户结果 中间可能因为网络原因 没推送到  我们需要重试    但是又不是无限制重试  我们可以设置一个阈值
            report.setSendCount(1);
//          发送给客户
            System.out.println("准备发送给接口  敏感词");
            sendReportService.sendSmsReport(report);*/
//todo        将本次的消息记录在 我们的日志中也就是 es
//            状态为2 发送失败
        submit.setReportState(2);
        submit.setErrorCode(InterfaceExceptionDict.RETURN_STATUS_DIRTY_ERROR);
        submit.setDescription(sensitiveWord.toString());

            return false;
        }
        return true;
    }
}
